<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.gxgyl.com All rights reserved.

// +----------------------------------------------------------------------
// | Author: Liuyu
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\common\model\shiyao;

use cores\BaseModel;

/**
 * 模型
 * Class
 * @package app\common\model
 */
class Project extends BaseModel {
	// 定义表名
	protected $name = 'shiyao_project';

	// 定义主键
	protected $pk = 'project_id';

	/**
	 * 追加字段
	 * @var array
	 */
	protected $append = ['level_text', 'status_text', 'pm_xiezhu'];
	public function getPmIdsAttr($value) {
		if($value!=null){
			$dd=json_decode($value, true);
		}else{
			$dd=[];
		}

		return $dd;
	}
public function getPmIdsAuditAttr($value) {
		if($value!=null){
			$dd=json_decode($value, true);
		}else{
			$dd=[];
		}

		return $dd;
	}
	public function getPmXiezhuAttr($value, $data) {
		if($data['pm_ids']!=null){
			$dd=json_decode($data['pm_ids'], true);
		}else{
			$dd=[];
		}
		
		if (!empty($dd)) {
			$dd = array_column($dd, 'label');
			$dd = implode(',', $dd);
		} else {
			$dd = '--';
		}

		return $dd;
	}

	public function getStatusTextAttr($value, $data) {

		switch ($data['status']) {
		case 1:
			$type = '审核通过';
			break;
		case 2:
			$type = '拒绝';
			break;

		default:
			$type = '待审核';
			break;
		}
		return $type;
	}

	public function getLevelTextAttr($value, $data) {

		switch ($data['level']) {
		case 1:
			$type = '一级';
			break;
		case 2:
			$type = '二级';
			break;

		default:
			// code...
			break;
		}
		return $type;
	}

	public function company() {
		return $this->hasOne('Company', 'company_id', 'company_id');
	}
	public function pm() {
		$module = self::getCalledModule();
		return $this->hasOne("app\\{$module}\\model\\User", 'user_id', 'pm_id');
	}
	public function pms() {
		$module = self::getCalledModule();
		return $this->belongsTo("app\\{$module}\\model\\User", 'pm_id');
	}
}
